package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Reply;
import cn.wolfcode.trip.base.mapper.ReplyMapper;
import cn.wolfcode.trip.base.query.CommentQuery;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ReplyServiceImpl implements IReplyService {

    @Autowired
    private ReplyMapper replysMapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());

        List<Reply> list = replysMapper.selectForList(qo);
        System.out.println(list);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Reply reply) {
        reply.setCreatetime(new Date());
        reply.setState(1);
        replysMapper.insert(reply);

    }

    @Override
    public List<Reply> getRepliesByCommentId(CommentQuery qo) {
        return replysMapper.selectRepliesByCommentId(qo);
    }
}
